package com.sgb.zhaocai.view.demand.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.OfferListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class OfferListAdapter  extends BaseRecycleAdapter<OfferListEntity> {


    public OfferListAdapter(Context context, List<OfferListEntity> datas) {
        super(context, R.layout.zc_offer_items, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        TextView offers = holder.itemView.findViewById(R.id.offer);
        TextView details = holder.itemView.findViewById(R.id.details);
        //报价
        offers.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.offers(datas.get(position));
            }
        });
        //详情
        details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.details(datas.get(position));
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, OfferListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView offerTypes = holder.itemView.findViewById(R.id.offer_type);
        TextView offers = holder.itemView.findViewById(R.id.offer);
        TextView offerTime = holder.itemView.findViewById(R.id.offer_time);
        TextView approachTime = holder.itemView.findViewById(R.id.approachTime);
        TextView offerName = holder.itemView.findViewById(R.id.offer_name);
        //需求类型：1、机械租赁；2、劳务用工；3、材料采购；4、分包计划；5、设备租赁
        switch (entity.getType()){
            case 1:
                offerTypes.setText("机械租赁");
                offerName.setText(entity.getName()+"");
                break;
            case 2:
                offerTypes.setText("劳务用工");
                offerName.setText(entity.getItemProject()+"");
                break;
            case 3:
                offerTypes.setText("材料采购");
                offerName.setText(entity.getName()+"");
                break;
            case 4:
                offerTypes.setText("分包计划");
                offerName.setText(entity.getItemProject()+"");
                break;
            case 5:
                offerTypes.setText("设备租赁");
                offerName.setText(entity.getName()+"");
                break;
        }
        offerTime.setText(DateUtils.stampToMinute(entity.getCreated())+"");
        //进厂时间
        approachTime.setText(DateUtils.timestampToDate(Long.parseLong(entity.getApproachTime()))+"");
        Log.e("tag时间", DateUtils.timestampToDate(Long.parseLong(entity.getApproachTime()))+" ----- "+DateUtils.timestampToDate(Long.parseLong(entity.getApproachTime()))+" 23:59:59");
        //经营帮项目是否公示（1：是；0：否）
        if (System.currentTimeMillis()<DateUtils.dateTo13Timestamp3(DateUtils.timestampToDate(Long.parseLong(entity.getApproachTime()))+" 23:59:59")){
            if (entity.getBisDeleted()==0){
                if (entity.getBannounce()==1||entity.getBisShow()==1){
                    offers.setVisibility(View.VISIBLE);
                }else {
                    offers.setVisibility(View.GONE);
                }
            }else {
                offers.setVisibility(View.GONE);
            }
        }else {
            offers.setVisibility(View.GONE);
        }
    }

    private OnItemStateOperate OnItemStateOperate;

    public void setOnItemStateOperate(OnItemStateOperate onItemStateOperate) {
        OnItemStateOperate = onItemStateOperate;
    }

    public interface OnItemStateOperate {

        void offers(OfferListEntity offerListEntity);

        void details(OfferListEntity offerListEntity);

    }
}
